{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.34781145  0.86291306  0.04930956  0.52610147  0.20504223  0.74134902]\n"
     ]
    }
   ],
   "source": [
    "#输入数据\n",
    "X = np.array([[1,0,0,0,0,0],\n",
    "              [1,0,1,0,0,1],\n",
    "              [1,1,0,1,0,0],\n",
    "              [1,1,1,1,1,1]])\n",
    "#标签\n",
    "Y = np.array([-1,1,1,-1])\n",
    "\n",
    "#权值初始化，3行1列，取值范围-1到1\n",
    "W = (np.random.random(6)-0.5)*2\n",
    "\n",
    "print(W)\n",
    "#学习率设置\n",
    "lr = 0.11\n",
    "#神经网络输出\n",
    "O = 0\n",
    "\n",
    "def update():\n",
    "    global X,Y,W,lr\n",
    "    O = np.dot(X,W) # shape:(3,1)\n",
    "    W_C = lr*(X.T.dot(Y-O))/int(X.shape[0])\n",
    "    W = W + W_C"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEACAYAAABI5zaHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHOxJREFUeJzt3Xl4VFWexvHvT4EGbRdABAYkcUMQFcQRsUWNtAvqKHSL\nLY7dOi2PuK80imJrdB59XNq91We0sWdEBXfFpXuEZmqUdkBUwhY2wSBKxIDQAgIGcuaPUzEhZKmk\nbtW9dev9PM99Ugk3t37cVN6cOvfcc8w5h4iIxMsuYRcgIiLBU7iLiMSQwl1EJIYU7iIiMaRwFxGJ\nIYW7iEgMBRLuZraXmb1sZgvNbIGZHRP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LTOKJzLZB3HAdtr\n/V58mnwdROqcplJnc8+pbmISEYmhKIyWERGRgCncRURiSOEuIhJDCncRkRhSuIuIxJDCXUQkhhTu\nIiIxpHAXEYmh/we6EbNEDOaaPgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2011ac9c4e0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for _ in range(10000):\n",
    "    update()#更新权值\n",
    "\n",
    "# 正样本\n",
    "x1 = [0,1]\n",
    "y1 = [1,0]\n",
    "#负样本\n",
    "x2 = [1,0]\n",
    "y2 = [1,0]\n",
    "xdata = np.linspace(-1,2)\n",
    "\n",
    "def calculate(x,root):\n",
    "    a = W[5]\n",
    "    b = W[2]+x*W[4]\n",
    "    c = W[0]+x*W[1]+x*x*W[3]      \n",
    "    if root==1:\n",
    "          return (-b+np.sqrt(b*b-4*a*c))/(2*a)\n",
    "          \n",
    "    if root==2:\n",
    "          return (-b-np.sqrt(b*b-4*a*c))/(2*a)\n",
    "    \n",
    "plt.figure()\n",
    "plt.plot(xdata,calculate(xdata,1),'r')\n",
    "plt.plot(xdata,calculate(xdata,2),'r')\n",
    "          \n",
    "plt.scatter(x1,y1,c='b')\n",
    "plt.scatter(x2,y2,c='y')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-1.  1.  1. -1.]\n"
     ]
    }
   ],
   "source": [
    "O = np.dot(X,W.T)\n",
    "print(O)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
